/**
  ETFDAQ Project
  \class TAGDAQ
  \brief The graphical user interface for the DAQ application
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2024-08-20
  \date 2024-08-20 last modified

  \copyright Copyright (c) 2024 IMP-CAS with LGPLv3 LICENSE
*/

#ifndef TAGDAQ_h
#define TAGDAQ_h

#include <QMainWindow>
#include <QMutex>
#include "daqstatus.h"

class QPushButton;
class QMessageBox;
class QLineEdit;
class QMenuBar;
class QLabel;
class TADAQThread;

class TAGDAQ : public QMainWindow{
  Q_OBJECT
public:
  /// \param dev is the device name of the vme controller
  TAGDAQ(const std::string &dev = "/dev/sis1100_00remote", QWidget *parent = nullptr);
  virtual ~TAGDAQ();

  virtual void run();
  virtual void updateDAQInfo(const QString &m);
  virtual void setDAQState(const QString &t);
  virtual void inited(); // update to inited state

  const char *startComment() const;
  const char *stopComment() const;
  virtual void prepareForANewRun(); ///< return to 'start a new run' status

  void lock(){ fMutex.lock(); }
  void unlock(){ fMutex.unlock(); }

public slots:
  virtual void init();
  virtual void start();
  virtual void pause();
  virtual void resume();
  virtual void stop();
  virtual void exit();

signals:
  void statusChanged(const EDAQSTA &sta); // no implementation for signal methods

protected:
  QPushButton *fInit, *fStart, *fPause, *fResume, *fStop, *fExit;
  QLabel *fDAQInfo, *fDAQState;
  QLineEdit *fStartComment, *fStopComment;
  QMenuBar *fMenuBar;
  QMessageBox *fAboutDiag; ///< show the author list
  EDAQSTA fDaqSta;
  QMutex fMutex; ///< for atomic actions of fDAQThread
  QPalette fPalette; ///< for setting window background colors
  TADAQThread *fDAQThread; ///< the worker thread
};

#endif
